package com.jcfk.system.controller;

import com.jcfk.common.security.annotation.AllowAnonymous;
import com.jcfk.common.web.domain.LoginParameter;
import com.jcfk.common.web.domain.RetResult;
import com.jcfk.system.domain.wechat.WeChatCreateRequest;
import com.jcfk.system.domain.wechat.send.WeChatSendRequest;
import com.jcfk.system.domain.wechat.send.WeChatSendSecretRequest;
import com.jcfk.system.service.SendWeChatMessageService;
import com.jcfk.system.service.SendWeChatService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.UnsupportedEncodingException;


@RestController
@RequestMapping("wx")
@Api(tags = "wx", description = "wx")
public class SendWeChatController {

    @Autowired
    private SendWeChatService sendWeChatService;

    @Autowired
    private SendWeChatMessageService sendWeChatMessageService;

    /**
     * 发送邮件
     */
    @PostMapping("sendwxChat")
    public RetResult<?> sendEmail(@RequestBody LoginParameter loginParameter) {
        // sendWeChatService.sendToWxCp(loginParameter.getLoginName());
        return RetResult.ok();
    }

    /**
     * 发送微信群聊消息
     *
     * @param weChatSendSecretRequest
     * @return
     */
    @PostMapping("sendMessageSecretChat")
    public RetResult<?> sendWxSecretChat(@RequestBody WeChatSendSecretRequest weChatSendSecretRequest) throws UnsupportedEncodingException {
        WeChatSendRequest weChatSendRequest = sendWeChatMessageService.dealSecretUrl(weChatSendSecretRequest);
        sendWeChatMessageService.sendWeChat(weChatSendRequest);
        return RetResult.ok();
    }

    /**
     * 发送微信群聊消息
     *
     * @param weChatSendRequest
     * @return
     */
    @PostMapping("sendMessageChat")
    public RetResult<?> sendWxChat(@RequestBody WeChatSendRequest weChatSendRequest) {
        sendWeChatMessageService.sendWeChat(weChatSendRequest);
        return RetResult.ok();
    }

    /**
     * 创建微信群聊
     *
     * @param weChatCreateRequest
     * @return
     */
    @AllowAnonymous
    @PostMapping("createMessageChatTeam")
    public RetResult<?> creatWxChatTeam(@RequestBody WeChatCreateRequest weChatCreateRequest) {
        sendWeChatMessageService.creatWxChatTeam(weChatCreateRequest);
        return RetResult.ok();
    }
}
